﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace MarketFunds
{
    public class NorthTotalData
    {
        public string TRADE_DATE { get; set; }
        public string MUTUAL_TYPE { get; set; }
        public string BOARD_TYPE { get; set; }
        public string MUTUAL_TYPE_NAME { get; set; }
        public string FUNDS_DIRECTION { get; set; }
        public string INDEX_CODE { get; set; }
        public string INDEX_NAME { get; set; }
        public string BOARD_CODE { get; set; }
        public string status { get; set; }
        public string dayNetAmtIn { get; set; }
        public string dayAmtRemain { get; set; }
        public string dayAmtThreshold { get; set; }
        public string f104 { get; set; }
        public string f105 { get; set; }
        public string f106 { get; set; }
        public string INDEX_f3 { get; set; }
        public string netBuyAmt { get; set; }
    }

    public class NorthTotalResult
    {
        public string pages { get; set; }
        public List<NorthTotalData> data { get; set; }
        public string count { get; set; }
    }

    public class NorthTotalRootObject
    {
        public string version { get; set; }
        public NorthTotalResult result { get; set; }
        public string success { get; set; }
        public string message { get; set; }
        public string code { get; set; }
    }
    class NorthTotalJSON
    {
        public NorthTotalRootObject NorthTotalRoot = null;
        public string GetPureNorthTotalJSON(string strJSON)
        {
            if (strJSON.Trim().Length == 0)
                return strJSON.Trim();
            //找到第一个( ;
            int nFirstPos = strJSON.IndexOf("(");

            int nLastPos = strJSON.LastIndexOf(")");
            string strTemp = strJSON.Substring(nFirstPos + 1, nLastPos - nFirstPos - 1);
            return strTemp;
        }
        public bool GetNorthTotalByJSON(string strJSON)
        {
            NorthTotalRootObject oro = JsonConvert.DeserializeObject<NorthTotalRootObject>(strJSON);
            if (oro.message != "ok")
            {
                Console.WriteLine("No data.");
                return false;
            }
            this.NorthTotalRoot = oro;
            NorthTotalResult rs = oro.result;
            string strPages = rs.pages;
            int nPages = Convert.ToInt16(strPages); //页数
            int nCount = Convert.ToInt16(rs.count); //总股票条数

            for (int i = 0; i < rs.data.Count; i++)
            {
                NorthTotalData data = rs.data[i];               
            }

            return true;
        }
    }
}
